package com.zhiqianbao.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhiqianbao.R;
import com.zhiqianbao.entity.RepayDataInfo.RepayListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hp on 2017/7/20.
 */
public class RepayAdapter extends BaseAdapter{
    public Context mContext;
    public List<RepayListBean> repayList=new ArrayList<>();
    public RepayAdapter (Context context,List<RepayListBean> repayList){
        mContext=context;
        this.repayList=repayList;
    }
    @Override
    public int getCount() {
        return repayList.size();
    }

    @Override
    public RepayListBean getItem(int position) {
        return repayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if(convertView==null){
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(mContext).inflate(R.layout.adapter_repay_layout,null);
            viewHolder.repay_time=(TextView)convertView.findViewById(R.id.repay_time);
            viewHolder.repay_state_img=(ImageView) convertView.findViewById(R.id.repay_state_img);
            convertView.setTag(viewHolder);
        }
        else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.repay_time.setText("到期还款日："+repayList.get(position).getPromiseDate());
        //0是未还款
        if(repayList.get(position).getState().equals("0")){
            viewHolder.repay_time.setTextColor(Color.parseColor("#0495FF"));
            viewHolder.repay_state_img.setImageResource(R.drawable.repay_clock_check);
        }
        else{
            viewHolder.repay_time.setTextColor(Color.parseColor("#999999"));
            viewHolder.repay_state_img.setImageResource(R.drawable.repay_clock_uncheck);
        }
        return convertView;
    }
    public class ViewHolder{
        TextView repay_time;
        ImageView repay_state_img;
    }
}
